package com.example.administrator.jokeyboarddemo;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import java.util.HashMap;
import java.util.Map;


public class MainActivity extends Activity implements View.OnClickListener {

    private Map<Integer,Integer> keyboard_number_map;
    private EditText edit_keyboard;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initKeyBoardValue();
    }

    private void initView() {
        edit_keyboard = (EditText)findViewById(R.id.edit_keyboard);
        findViewById(R.id.tv_number_zero).setOnClickListener(this);
        findViewById(R.id.tv_number_one).setOnClickListener(this);
        findViewById(R.id.tv_number_two).setOnClickListener(this);
        findViewById(R.id.tv_number_three).setOnClickListener(this);
        findViewById(R.id.tv_number_four).setOnClickListener(this);
        findViewById(R.id.tv_number_five).setOnClickListener(this);
        findViewById(R.id.tv_number_sex).setOnClickListener(this);
        findViewById(R.id.tv_number_seven).setOnClickListener(this);
        findViewById(R.id.tv_number_eight).setOnClickListener(this);
        findViewById(R.id.tv_number_nine).setOnClickListener(this);
    }

    /**
     * 初始化键盘所有key value
     */

    public void initKeyBoardValue(){
        keyboard_number_map = new HashMap<>();
        keyboard_number_map.put(R.id.tv_number_zero,0);
        keyboard_number_map.put(R.id.tv_number_one,1);
        keyboard_number_map.put(R.id.tv_number_two,2);
        keyboard_number_map.put(R.id.tv_number_three,3);
        keyboard_number_map.put(R.id.tv_number_four,4);
        keyboard_number_map.put(R.id.tv_number_five,5);
        keyboard_number_map.put(R.id.tv_number_sex,6);
        keyboard_number_map.put(R.id.tv_number_seven,7);
        keyboard_number_map.put(R.id.tv_number_eight,8);
        keyboard_number_map.put(R.id.tv_number_nine,9);
    }


    @Override
    public void onClick(View v) {
      int value = keyboard_number_map.get(v.getId());
        Log.e("aaa", "获取的值"+value);
        edit_keyboard.getText().append(value+"");
    }
}
